/**
Author ffpan
Date 2010-04-04
Version 1.0
**/
$(document).ready(function(){
	//初始化中介的tips
	initTips($("#agent_name"));
	initTips($("#s_plaza"));
	initTips($("#r_plaza"));
	
	

	$("#rentorsell").val(0);
	
	var lastel = $("#switchbody1");
	var lasttitle = $("#s1");

	/*$("#switch li").each(function(){
		$(this).bind("click" , function(){
			var el = $(document.getElementById($(this).attr("forshow")));
			if(lastel!=null){lastel.css("display" , "none");}
			el.css("display" , "");
			lastel = el;
			if(lasttitle!=null){lasttitle.removeClass("licurrent");}
			$(this).addClass("licurrent");
			lasttitle = $(this);

			//是否显示地图和出租出售列表
			if($(this).attr("forshow")!="switchbody1"){
				$("#radiodiv1").css("display" , "none");
				$("#radiodiv2").css("display" , "");
			}else{
				$("#radiodiv1").css("display" , "");
				$("#radiodiv2").css("display" , "none");
			}

			//是否放大框框
			if($(this).attr("forshow")=="switchbody3"){
				$("#m_top").removeClass("m_top").addClass("m_top2");
				$("#searchbox").css("height" , "183px");
			}else{
				$("#m_top").removeClass("m_top2").addClass("m_top");
				$("#searchbox").css("height" , "108px")
			}
		});
	});*/

	

	//initialize();

	//表单提交，清空提示语句
	$("#index_sform1").bind("submit" , function(){
		if($("#agent_name").val() == $("#agent_name").attr("tips")){
			$("#agent_name").val("");
			return true;
		}
	});

	$("#agent_order").bind("change" , function(){
		var opt =$(this).val(); 
		ajaxAgent(opt , 1);
	});
	
	if($("#anextpage")){
		checkpage();
		$("#aprevpage").bind("click" , function(){
			p = parseInt($("#anowpage").val())-1;
			$("#anowpage").val(p);
			$("#showpage").html(p);
			checkpage();
			ajaxAgent($("#agent_order").val() , p);
		});
		
		$("#anextpage").bind("click" , function(){
			p = parseInt($("#anowpage").val())+1;
			$("#anowpage").val(p);
			$("#showpage").html(p);
			checkpage();
			ajaxAgent($("#agent_order").val() , p);
		});
	}

	
	checkpage();

	$("#prepage").bind("click" , function(){
		if($("#s_page").val()=="1"){return;}
		var key =$("#key").val(); 
		var page = parseInt($("#s_page").val());
		 $("#s_page").val(page-1);
		 $("#pn").html(page-1);
		 ajaxAgent($("#agent_order").val() , page);
		 checkpage();
	});

	
	$("#nextpage").bind("click" , function(){
		if($("#s_page").val()==$("#pagetotal").val()){return;}
		var key =$("#key").val(); 
		var page = parseInt($("#s_page").val());
		$("#s_page").val(page+1);
		$("#pn").html(page+1);
		 ajaxAgent($("#agent_order").val() , page);
		 checkpage();
	});
	

	
	if($("#sbtn")){
		$("#sbtn").bind("click" , function(){
			if($("#skey").val()==$("#skey").attr("tips")){$("#skey").val("");}
			ajaxAgent($("#agent_order").val() , 1 , $("#skey").val());
		});
	}
	
	/*function checkpage(){
		var nowpage = parseInt($("#anowpage").val());
		var totalpage = parseInt($("#atotalpage").val());
		if(nowpage==1){
			$("#aprevpage").css("visibility" , "hidden");
		}else{
			$("#aprevpage").css("visibility" , "visible");
		}
		if(nowpage==totalpage){
			$("#anextpage").css("visibility" , "hidden");
		}else{
			$("#anextpage").css("visibility" , "visible");
		}
	}*/

	function checkpage(){
		if($("#s_page").val()==1){$("#prepage").css("visibility" , "hidden");}else{$("#prepage").css("visibility" , "visible");}
		if($("#s_page").val()==$("#pagetotal").val()){$("#nextpage").css("visibility" , "hidden");}else{$("#nextpage").css("visibility" , "visible");}
	}
	
	function ajaxAgent(order , page , key){
	    if(key==undefined){key = "";}
		$.ajax({
			type:"GET",
			url:"ajax_agent_order.php",
			data:"order="+order+"&p="+page+"&key="+key,
			success:function(json){
				var str = "";
				var json = eval(json);
				$.each(json, function(k){
					str += "<li><a href='agent_detail.php?aid="+json[k]["id"]+"' target='blank'><img src='_skins/tplimgs/avatar_popular.jpg'  border='0' title="+json[k]["name"]+"  width='56' style='margin-bottom:2px;'/></a><span class='numberbg'>"+json[k]["number"]+"</span></a><a href='agent_detail.php?aid='"+json[k]["id"]+"' target='blank'><span>"+json[k]["name"]+"</span></a><img src='_skins/tplimgs/alpha.png' class='starbg star"+json[k]["stars"]+"' title='积分:"+json[k]["scores"]+"' /><span class='grayw'>"+json[k]["lastlogin"]+"</span></li>";
				});
				$("#alistdiv").html(str);
			}
		});
	}

	//切换到房源搜索
	$("#rentorsell").bind("change" , function(){
		var opt = $(this).val();
		if(opt==0){
			$("#sell_search").css("display", "");
			$("#rent_search").css("display", "none");
			$("#index_sform2").attr("action" , "sellhouse_list.php");
		}else{
			$("#sell_search").css("display", "none");
			$("#rent_search").css("display", "");
			$("#index_sform2").attr("action" , "renthouse_list.php?idxs=1");
		}
	});

	$("#index_sform2").bind("submit" , function(){
		if($("#s_plaza").val() == $("#s_plaza").attr("tips")){
			$("#s_plaza").val("");
			return true;
		}
	});

	//google baidu taobao搜索框显示
	var olastel = $("#outsdiv_google");
	$("#outdiv_switch input").each(function(){
		$(this).bind("click" , function(){
			var el = $(document.getElementById($(this).attr("forshow")));
			if(olastel!=null){olastel.css("display" , "none");}
			el.css("display" , "");
			olastel = el;
		});
	});

	
	//最新房源切换效果
	if($("#indexnew_list")){
		var n_lastel = $("#n_selllist");
		var n_lastel_title = $("#indexnew_list li:first");
		
		$("#indexnew_list").bind("mouseover" , function(e){
			var el = e.target;
			if(el.tagName=="LI"){
				n_lastel_title.removeClass("new_sel");
				$(el).addClass("new_sel");	
				n_lastel_title=$(el);
				
				var forshow = $($(el).attr("forshow"));
				n_lastel.css("display" , "none");
				forshow.css("display" , "");
				n_lastel = forshow;
			}
		});
	}


	//最新房源切换效果
	if($("#index_policy")){
		var p_lastel = $("#newslist");
		var p_lastel_title = $("#index_policy li:first");
		
		$("#index_policy").bind("mouseover" , function(e){
			var el = e.target;
			if(el.tagName=="LI"){
				p_lastel_title.removeClass("psel");
				$(el).addClass("psel");	
				p_lastel_title=$(el);
				$(el).css("cursor" , "pointer");

				var forshow = $($(el).attr("forshow"));
				p_lastel.css("display" , "none");
				forshow.css("display" , "");
				p_lastel = forshow;
			}
		});
	}
	

}); 



function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"));
	map.setCenter(new GLatLng(31.980, 120.894), 13);

  }
}


//
//window.onunload=GUnload;



